@echo off
chcp 65001 >nul
REM uninstall.bat - 使用UTF-8编码保存此文件

echo 正在移除扫码枪服务...

REM 获取当前目录
set "CURRENT_DIR=%~dp0"
set "EXE_NAME=SerialInput.exe"
set "EXE_PATH=%CURRENT_DIR%%EXE_NAME%"

REM 检查可执行文件是否存在
if not exist "%EXE_PATH%" (
    echo 警告: 找不到 %EXE_NAME%
    echo 将尝试直接从注册表移除...
) else (
    echo 找到程序: %EXE_PATH%
)

REM 停止服务
echo 停止服务...
taskkill /f /im %EXE_NAME% 2>nul

REM 等待进程完全停止
timeout /t 2 /nobreak >nul

REM 移除开机自启
echo 移除开机自启...
if exist "%EXE_PATH%" (
    "%EXE_PATH%" --uninstall
) else (
    REM 直接操作注册表
    reg delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "ScannerService" /f 2>nul
)

echo.
echo 卸载完成！
echo 扫码枪服务已从开机自启中移除

echo.
pause
